package com.example.text3;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

public class YourActivity extends AppCompatActivity {
    private String clickedNumber = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 数字按钮点击事件
        Button btn0 = findViewById(R.id.buttonview_number_0);
        Button btn1 = findViewById(R.id.buttonview_number_1);
        Button btn2 = findViewById(R.id.buttonview_number_2);
        Button btn3 = findViewById(R.id.buttonview_number_3);
        Button btn4 = findViewById(R.id.buttonview_number_4);
        Button btn5 = findViewById(R.id.buttonview_number_5);
        Button btn6 = findViewById(R.id.buttonview_number_6);
        Button btn7 = findViewById(R.id.buttonview_number_7);
        Button btn8 = findViewById(R.id.buttonview_number_8);
        Button btn9 = findViewById(R.id.buttonview_number_9);

        btn0.setOnClickListener(v -> clickedNumber += "0");
        btn1.setOnClickListener(v -> clickedNumber += "1");
        btn2.setOnClickListener(v -> clickedNumber += "2");
        btn3.setOnClickListener(v -> clickedNumber += "3");
        btn4.setOnClickListener(v -> clickedNumber += "4");
        btn5.setOnClickListener(v -> clickedNumber += "5");
        btn6.setOnClickListener(v -> clickedNumber += "6");
        btn7.setOnClickListener(v -> clickedNumber += "7");
        btn8.setOnClickListener(v -> clickedNumber += "8");
        btn9.setOnClickListener(v -> clickedNumber += "9");

        // Remove按钮点击事件
        Button btnRemove = findViewById(R.id.buttonview_remove);
        btnRemove.setOnClickListener(v -> {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Confirm")
                    .setMessage("Are you sure to clean the number?")
                    .setPositiveButton("Yes", (dialog, which) -> clickedNumber = "")
                    .setNegativeButton("No", null)
                    .show();
        });

        // Input按钮点击事件
        Button btnInput = findViewById(R.id.buttonview_input);
        btnInput.setOnClickListener(v -> {
            Toast.makeText(this, "You have input number " + clickedNumber, Toast.LENGTH_SHORT).show();
        });
    }
}